package com.studyspringcloud.product.service.impl;

import com.studyspringcloud.product.enums.ProductStatusEnum;
import com.studyspringcloud.product.model.ProductCategory;
import com.studyspringcloud.product.model.ProductInfo;
import com.studyspringcloud.product.repository.ProductCategoryRepository;
import com.studyspringcloud.product.repository.ProductInfoRepository;
import com.studyspringcloud.product.service.ProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ProductServiceImpl implements ProductService {

    @Autowired
    private ProductCategoryRepository productCategoryRepository;

    @Autowired
    private ProductInfoRepository productInfoRepository;

    @Override
    public List<ProductInfo> findByStatus(Integer status) {
        return productInfoRepository.findByStatus(status);
    }

    @Override
    public List<ProductCategory> findByTypeIn(List<Integer> typeList) {
        return productCategoryRepository.findByTypeIn(typeList);
    }

    @Override
    public ProductCategory findCategoryById(Integer id) {
        return productCategoryRepository.getOne(id);
}

    @Override
    public ProductInfo findInfoById(Integer id) {
        return productInfoRepository.getOne(id);
    }

    public List<ProductInfo> findUpAll(){
        return productInfoRepository.findByStatus(ProductStatusEnum.up.getCode());
    }

}
